import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { UserInfo } from './main.d'

export const useMainStore = defineStore(
  'main', // id
  () => {
    // 样例
    const count = ref(0)
    // 用户集合
    const userList = ref<UserInfo[]>([])
    // 用户
    const userInfo = ref<UserInfo | null>(null)

    // 计算属性
    const doubleCount = computed(() => {
      return count.value * 2
    })

    // 方法
    const increment = () => {
      count.value += 1
    }

    return { count, userList, userInfo, doubleCount, increment }
  },
  {
    // 持久化设置（默认存储sessionStorage，https://seb-l.github.io/pinia-plugin-persist/advanced/partial-state.html）
    persist: { enabled: true },
  },
)
